Person.prototype.sayName = function () {
  console.log(this.name);
}

function Person(name, age) {
  this.name = name
  this.age = 18

  // return []  如果这个是引用类型就输出这个，反之输出原来的
}

// let p = new Person('张三', 18)
// console.log(p);   // Person { name: '张三', age: 18 }
// p.sayName();     // 张三



function myNew(constructor, ...args) {
  let obj = {}
  // obj.__proto__ = constructor.prototype
  obj = Object.create(constructor.prototype)
  const result = constructor.apply(obj, args)
  return result instanceof Object ? result : obj
}

let p = myNew(Person, '张三', 18)

console.log(p);   // Person { name: '张三', age: 18 }
p.sayName();     // 张三